package com.fastshopping.model.controller;

import com.fastshopping.model.service.ShareService;
import com.fastshopping.order.pojo.Share;
import com.wink.entity.Result;
import com.wink.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Name: 李袁勇
 * @Date: 2020/6/6 10:10
 * @Version: 1.0
 **/

/*
* 共享模板*/

@RestController
@RequestMapping("/share")
public class ShareController {
    @Autowired
    private ShareService shareService;

    /*
    * */
    @RequestMapping("/findAllShare")
    public Result findAllShare(int user_id){
        try {
            List <Share> allShare = shareService.findAllShare(user_id);
            return new Result(true, StatusCode.OK,"成功",allShare);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"失败");
        }
    }

    /*
    * */
    @RequestMapping("/findAllState")
    public Result findAllState(int user_id,int state){
        try {
            List <Share> byState = shareService.findByState(user_id,state);
            return new Result(true, StatusCode.OK,"成功",byState);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"失败");
        }
    }

    /*
    * 店铺添加模板*/
    @RequestMapping("/addShare")
    public Result addShare(@RequestBody Share share){
        try {
            shareService.addShare(share);
            return new Result(true,StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.OK,"添加失败");
        }
    }

    /*
    *模板上架*/
    @RequestMapping("/shelves")
    public Result shelves(int model_id){
        try {
            shareService.addModel(model_id);
            return new Result(true,StatusCode.OK,"上架成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,e.getMessage());
        }
    }
    /*
    * 模板下架*/
    @RequestMapping("/theShelves")
    public Result theShelves(int model_id){
        try {
            shareService.theShelves(model_id);
            return new Result(true,StatusCode.OK,"下架成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"下架失败");
        }
    }
}
